﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Cs2102BookingSystem.Models;
using System.Globalization;

namespace Cs2102BookingSystem.Controllers
{
    public class SearchController : Controller
    {
        //
        BookingEntities _db = new BookingEntities();

        // GET: /Search/

        public ActionResult MainSearch()
        {
            return View();
        }

        [HttpPost]
        public ActionResult MainSearch(SearchModels form)
        {
            return null;
        }

        public object SearchResult(SearchModels form)
        {
            if (String.IsNullOrEmpty(form.Search))
                ModelState.AddModelError("Search", "Empty input");

            var searchString1 = form.Search;
            var resultCount = 0;
            var listOfHotel = from hotel in _db.HOTEL
                              where hotel.HOTEL_NAME.ToLower().Contains(searchString1.ToLower()) ||
                                    hotel.COUNTRY.ToLower().Contains(searchString1.ToLower()) ||
                                    hotel.BRANCHNAME.ToLower().Contains(searchString1.ToLower())
                              select new
                              {
                                  Hotel = hotel.HOTEL_NAME,
                                  Branch = hotel.BRANCHNAME,
                                  Country = hotel.COUNTRY,
                                  Address = hotel.ADDRESS,
                                  District = hotel.DISTRICT
                              };
            resultCount = listOfHotel.ToList().Count();
            if (listOfHotel == null)
            {
                ViewData["Message"] = "No Result Found!";
                ViewData["searchResult"] = "";
            }
            else
            {
                ViewData["Message"] = resultCount + " results found for " + searchString1;
                ViewData["searchResult"] = listOfHotel;
            }
            return View();
        }

        public ActionResult AdvancedSearch()
        {
            try
            {
                return View();
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }
         
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AdvancedSearch(FormCollection form)
        {
            try
            {
                var radioButtonResult = form["radioButtonSearch"];

                if (radioButtonResult == "roomSearch")
                {
                    return RedirectToAction( "AdvancedRoomSearch","Search");
                }
                else if (radioButtonResult == "facilitySearch")
                {
                    return RedirectToAction("AdvancedFacilitiesSearch", "Search");
                }
                else
                {
                     return RedirectToAction("Error", "Home");
                }
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }

        }


        public ActionResult AdvancedRoomSearch()
        {
            try
            {

                HOTEL_ROOM_INFO _detail_model = new HOTEL_ROOM_INFO();

                var countrylist = new SelectList((from detail in _db.HOTEL_ROOM_INFO
                                                  select new SelectListItem
                                                  {
                                                      Text = detail.COUNTRY

                                                  }).Distinct(), "Text", "Text", _detail_model.COUNTRY);

                SelectList hotellist = new SelectList("");
                SelectList branchlist = new SelectList("");
                SelectList districtlist = new SelectList("");
                SelectList roomlist = new SelectList("");
                SelectList bedlist = new SelectList("");

                ViewData["countrylist"] = countrylist;
                ViewData["hotel_list"] = hotellist;
                ViewData["branch_list"] = branchlist;
                ViewData["district_list"] = districtlist;
                ViewData["roomlist"] = roomlist;
                ViewData["bedlist"] = bedlist;
                ViewData["Submitted"] = 0;

                return View(_detail_model);
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AdvancedRoomSearch(FormCollection form)
        {
            try
            {

                HOTEL_ROOM_INFO _detail_model = new HOTEL_ROOM_INFO();
                _detail_model.COUNTRY = form.Get("COUNTRY");
                _detail_model.HOTEL_NAME = form.Get("HOTEL_NAME");
                _detail_model.BRANCHNAME = form.Get("BRANCHNAME");
                _detail_model.DISTRICT = form.Get("DISTRICT");
                _detail_model.BEDTYPE = form.Get("BEDTYPE");
                _detail_model.ROOMTYPE = form.Get("ROOMTYPE");


                var countrylist = new SelectList((from hotel in _db.HOTEL_ROOM_INFO
                                                  orderby hotel.COUNTRY.ToLower()
                                                  select new SelectListItem
                                                  {
                                                      Text = hotel.COUNTRY
                                                  }).Distinct(), "Text", "Text", _detail_model.COUNTRY);


                SelectList hotellist = new SelectList((from hotel in _db.HOTEL_ROOM_INFO
                                                       where hotel.COUNTRY.Contains(_detail_model.COUNTRY)
                                                       select new SelectListItem
                                                       {
                                                           Text = hotel.HOTEL_NAME,

                                                       }).Distinct(), "Text", "Text", _detail_model.HOTEL_NAME);

                SelectList roomlist = new SelectList((from room in _db.HOTEL_ROOM_INFO
                                                      where room.COUNTRY == _detail_model.COUNTRY
                                                      select new SelectListItem
                                                      {
                                                          Text = room.ROOMTYPE
                                                      }).Distinct(),"Text","Text",_detail_model.ROOMTYPE);

                SelectList bedlist = new SelectList((from bed in _db.HOTEL_ROOM_INFO
                                                     where bed.COUNTRY == _detail_model.COUNTRY
                                                     select new SelectListItem
                                                     {
                                                         Text = bed.BEDTYPE
                                                     }).Distinct(),"Text","Text",_detail_model.BEDTYPE);

                                                     
                SelectList branchlist = new SelectList("");
                SelectList districtlist = new SelectList("");


                if (string.IsNullOrWhiteSpace(_detail_model.HOTEL_NAME) &&
                    string.IsNullOrWhiteSpace(_detail_model.BRANCHNAME) &&
                    (!string.IsNullOrWhiteSpace(_detail_model.DISTRICT)))
                {
                    hotellist = new SelectList((from hotel in _db.HOTEL_ROOM_INFO
                                                where hotel.COUNTRY.Contains(_detail_model.COUNTRY) &&
                                                    hotel.DISTRICT == _detail_model.DISTRICT

                                                select new SelectListItem
                                                {
                                                    Text = hotel.HOTEL_NAME,

                                                }).Distinct(), "Text", "Text", _detail_model.HOTEL_NAME);

                    districtlist = new SelectList((from district in _db.HOTEL_ROOM_INFO
                                                   where district.COUNTRY == _detail_model.COUNTRY
                                                   select new SelectListItem
                                                   {
                                                       Text = district.DISTRICT
                                                   }).Distinct(), "Text", "Text", _detail_model.DISTRICT);


                }
                else if (string.IsNullOrWhiteSpace(_detail_model.HOTEL_NAME) &&
                    string.IsNullOrWhiteSpace(_detail_model.BRANCHNAME))
                {
                    districtlist = new SelectList((from district in _db.HOTEL_ROOM_INFO
                                                   where district.COUNTRY == _detail_model.COUNTRY
                                                   select new SelectListItem
                                                   {
                                                       Text = district.DISTRICT
                                                   }).Distinct(), "Text", "Text", _detail_model.DISTRICT);
                }
                else if (string.IsNullOrWhiteSpace(_detail_model.BRANCHNAME) &&
                       (!string.IsNullOrWhiteSpace(_detail_model.HOTEL_NAME)) &&
                           (!string.IsNullOrWhiteSpace(_detail_model.DISTRICT)))
                {
                    branchlist = new SelectList((from branch in _db.HOTEL_ROOM_INFO
                                                 where branch.COUNTRY == _detail_model.COUNTRY &&
                                                       branch.HOTEL_NAME == _detail_model.HOTEL_NAME &&
                                                       branch.DISTRICT == _detail_model.DISTRICT
                                                 select new SelectListItem
                                                 {

                                                     Text = branch.BRANCHNAME
                                                 }).Distinct(), "Text", "Text", _detail_model.BRANCHNAME);

                    districtlist = new SelectList((from district in _db.HOTEL_ROOM_INFO
                                                   where district.COUNTRY == _detail_model.COUNTRY
                                                   select new SelectListItem
                                                   {
                                                       Text = district.DISTRICT
                                                   }).Distinct(), "Text", "Text", _detail_model.DISTRICT);

                }

                else if (string.IsNullOrWhiteSpace(_detail_model.BRANCHNAME) &&
                        (!string.IsNullOrWhiteSpace(_detail_model.HOTEL_NAME)))
                {
                    branchlist = new SelectList((from branch in _db.HOTEL_ROOM_INFO
                                                 where branch.COUNTRY == _detail_model.COUNTRY &&
                                                       branch.HOTEL_NAME == _detail_model.HOTEL_NAME
                                                 select new SelectListItem
                                                 {

                                                     Text = branch.BRANCHNAME
                                                 }).Distinct(), "Text", "Text", _detail_model.BRANCHNAME);

                    districtlist = new SelectList((from district in _db.HOTEL_ROOM_INFO
                                                   where district.COUNTRY == _detail_model.COUNTRY &&
                                                         district.HOTEL_NAME == _detail_model.HOTEL_NAME
                                                   select new SelectListItem
                                                   {
                                                       Text = district.DISTRICT
                                                   }).Distinct(), "Text", "Text", _detail_model.DISTRICT);

                }
                else if ((!string.IsNullOrWhiteSpace(_detail_model.BRANCHNAME) &&
                        (!string.IsNullOrWhiteSpace(_detail_model.HOTEL_NAME))))
                {
                    roomlist = new SelectList((from room in _db.HOTEL_ROOM_INFO
                                               where room.COUNTRY == _detail_model.COUNTRY &&
                                                     room.HOTEL_NAME == _detail_model.HOTEL_NAME &&
                                                     room.BRANCHNAME == _detail_model.BRANCHNAME

                                               select new SelectListItem
                                               {
                                                   Text = room.ROOMTYPE
                                               }).Distinct(), "Text", "Text", _detail_model.ROOMTYPE);

                    bedlist = new SelectList((from bed in _db.HOTEL_ROOM_INFO
                                              where bed.COUNTRY == _detail_model.COUNTRY &&
                                                     bed.HOTEL_NAME == _detail_model.HOTEL_NAME &&
                                                     bed.BRANCHNAME == _detail_model.BRANCHNAME
                                              select new SelectListItem
                                              {
                                                  Text = bed.BEDTYPE
                                              }).Distinct(), "Text", "Text", _detail_model.BEDTYPE);

                    branchlist = new SelectList((from branch in _db.HOTEL_ROOM_INFO
                                                 where branch.COUNTRY == _detail_model.COUNTRY &&
                                                       branch.HOTEL_NAME == _detail_model.HOTEL_NAME
                                                 select new SelectListItem
                                                 {

                                                     Text = branch.BRANCHNAME
                                                 }).Distinct(), "Text", "Text", _detail_model.BRANCHNAME);
                }
              

                int submit = 0;

                if (string.IsNullOrEmpty(form["submit1"]))
                {

                    ViewData["countrylist"] = countrylist;
                    ViewData["hotel_list"] = hotellist;
                    ViewData["branch_list"] = branchlist;
                    ViewData["district_list"] = districtlist;
                    ViewData["roomlist"]= roomlist;
                    ViewData["bedlist"] = bedlist;

                    ViewData["Submitted"] = submit;
                    return View(_detail_model);

                }
                else
                {


                    if (string.IsNullOrWhiteSpace(_detail_model.COUNTRY))
                    {
                        ModelState.AddModelError("COUNTRY", "Please select a country");
                        ViewData["countrylist"] = countrylist;
                        ViewData["hotel_list"] = hotellist;
                        ViewData["branch_list"] = branchlist;
                        ViewData["district_list"] = districtlist;
                        ViewData["roomlist"] = roomlist;
                        ViewData["bedlist"] = bedlist;
                        ViewData["Submitted"] = submit;
                        return View(_detail_model);
                    }
                    else
                    {
                        submit = 1;

                        ViewData["countrylist"] = countrylist;
                        ViewData["hotel_list"] = hotellist;
                        ViewData["branch_list"] = branchlist;
                        ViewData["district_list"] = districtlist;
                        ViewData["roomlist"] = roomlist;
                        ViewData["bedlist"] = bedlist;
                        ViewData["Submitted"] = submit;
                        return View(_detail_model);

                    }

                }
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }

        }

        public ActionResult AdvancedFacilitiesSearch()
        {

            try
            {

                FACILITIES _detail_model = new FACILITIES();

                var submitted = 0;
                var facilitylist = new SelectList((from detail in _db.FACILITIES
                                                  select new SelectListItem
                                                  {
                                                      Text = detail.FACILITY

                                                  }).Distinct(), "Text", "Text", _detail_model.FACILITY);


                ViewData["_submittedFacilities"] = submitted;
                ViewData["facilitylist"] = facilitylist;

                return View(_detail_model);
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }
        }

         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AdvancedFacilitiesSearch(FormCollection form)
        {
            try
            {
                FACILITIES facility_model = new FACILITIES();
                var submitted = 1;
                facility_model.FACILITY = form.Get("FACILITY");

                var facilitylist = new SelectList((from detail in _db.FACILITIES
                                                   select new SelectListItem
                                                   {
                                                       Text = detail.FACILITY

                                                   }).Distinct(), "Text", "Text", facility_model.FACILITY);

                ViewData["_submittedFacilities"] = submitted;
                ViewData["facilitylist"] = facilitylist;
                return View(facility_model);
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }

        }

         public ActionResult AdvancedFacilitiesSearchResult(string _facility)
         {
             ViewData.Model = (from facility in _db.FACILITIES
                               where facility.FACILITY == _facility
                               select facility).ToList();

             int noResultFound = (from facility in _db.FACILITIES
                                  where facility.FACILITY == _facility
                                  select facility).Count();

             ViewData["noResultFound"] = noResultFound;
             return View();
         }


        public ActionResult ViewDetails(string hotelName, string branchName, string country)
        {
            string message = "Welcome to " + hotelName;
            int roomCount = 0;
            int facilitiesCount = 0;
            var hotelDetail = getHotelDetail(hotelName, branchName, country);
            var roomTypes = getRoomDetails(hotelName, branchName, country,ref roomCount);
            var facilitiesTypes = getFacilitiesDetails(hotelName, branchName, country, ref facilitiesCount);
            var HOTELIMAGE = getImageURL(hotelName, branchName, country);

            ViewData["hotelDetail"] = hotelDetail;
            ViewData["hoteName"] = hotelName;    
            ViewData["country"] = country;
            ViewData["branchName"] = branchName;

            if (roomCount != 0)
            {
                ViewData["roomDetails"] = roomTypes;
            }
            
                ViewData["numberOfRooms"] = roomCount;
            


            if (facilitiesCount != 0)
            {
                ViewData["facilitiesDetails"] = facilitiesTypes;
            }

            ViewData["numberOfFacilities"] = facilitiesCount;
            ViewData["message"] = message;
            ViewData["HOTELIMAGE"] = HOTELIMAGE;

            return View();

        }

        private object getHotelDetail(string hotelName, string branchName, string country)
        {
            try
            {
                var hotelDetail = (from hotel in _db.HOTEL
                                   where hotel.HOTEL_NAME.Contains(hotelName)
                                      && hotel.BRANCHNAME.Contains(branchName)
                                      && hotel.COUNTRY.Contains(country)
                                   select hotel);

                return hotelDetail.First();
            }
            catch
            {
                return null;
            }

        }

        private object getRoomDetails(string hotelName , string branchName, string country, ref int roomCount)
        {
            var roomReturnList = (from room in _db.ROOM
                                  where room.H_BRANCHNAME.Contains(branchName)
                                         && room.H_NAME.Contains(hotelName)
                                         && room.H_COUNTRY.Contains(country)
                                   select new
                                   {
                                      ROOMIMAGE = room.ROOMIMAGE,
                                      ROOMTYPE = room.ROOMTYPE,
                                      PRICE = room.PRICE
                                    }); 

            roomCount = (from room in _db.ROOM
                               where room.H_BRANCHNAME.Contains(branchName)
                                         && room.H_NAME.Contains(hotelName)
                                         && room.H_COUNTRY.Contains(country)
                                  select room).Count();

            return roomReturnList;

        }

        private object getFacilitiesDetails(string hotelName, string branchName, string country, ref int facilitiesCount)
        {

            var facilityReturnList = (from facilities in _db.FACILITIES
                                      where facilities.H_BRANCHNAME.Contains(branchName)
                                         && facilities.H_NAME.Contains(hotelName)
                                         && facilities.H_COUNTRY.Contains(country)
                                      select new
                                      {
                                          FACILITYIMAGE = facilities.FACILITYIMAGE,
                                          Facilities= facilities.FACILITY,
                                          Description = facilities.DESCRIPTION
                                      });

            facilitiesCount = (from facilities in _db.FACILITIES
                                      where facilities.H_BRANCHNAME.Contains(branchName)
                                         && facilities.H_NAME.Contains(hotelName)
                                         && facilities.H_COUNTRY.Contains(country)
                                      select facilities).Count();

            return facilityReturnList;

        }

        private object getImageURL(string hotelName, string branchName, string country)
        {
            var HOTELIMAGE = (from hotel in _db.HOTEL
                              where hotel.HOTEL_NAME.Contains(hotelName)
                                 && hotel.BRANCHNAME.Contains(branchName)
                                 && hotel.COUNTRY.Contains(country)
                              select hotel.HOTELIMAGE);


            return HOTELIMAGE;

        }
        public ActionResult viewPartialHotelDetail()
        {
            return View();

        }

        public ActionResult AdvancedSearchResult(string _country, string _hotel_name, string _branch, string _district, string _roomType , string _bedType)
        {
            try
            {
                int noResultFound = 0;
                if (string.IsNullOrWhiteSpace(_hotel_name) &&
                    string.IsNullOrWhiteSpace(_branch) &&
                    string.IsNullOrWhiteSpace(_district) &&
                    string.IsNullOrWhiteSpace(_roomType) &&
                    string.IsNullOrWhiteSpace(_bedType))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country
                                     select room).Count();
                }
                else if ((!string.IsNullOrWhiteSpace(_hotel_name) &&
                         string.IsNullOrWhiteSpace(_branch) &&
                        (!string.IsNullOrWhiteSpace(_district)) &&
                         string.IsNullOrWhiteSpace(_roomType) &&
                         string.IsNullOrWhiteSpace(_bedType)))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                           room.DISTRICT == _district
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                          room.DISTRICT == _district
                                     select room).Count();
                }
                else if ((string.IsNullOrWhiteSpace(_hotel_name) &&
                         string.IsNullOrWhiteSpace(_branch) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         string.IsNullOrWhiteSpace(_roomType) &&
                         (!string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                            room.BEDTYPE == _bedType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                           room.BEDTYPE == _bedType
                                     select room).Count();
                }
                else if (((string.IsNullOrWhiteSpace(_hotel_name) &&
                         string.IsNullOrWhiteSpace(_branch) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         (!string.IsNullOrWhiteSpace(_roomType)) &&
                         string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                            room.ROOMTYPE == _roomType
                                      select room).ToList();


                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                           room.ROOMTYPE == _roomType
                                     select room).Count();
                }
                else if (((string.IsNullOrWhiteSpace(_hotel_name) &&
                         string.IsNullOrWhiteSpace(_branch) &&
                         (!string.IsNullOrWhiteSpace(_district)) &&
                         (string.IsNullOrWhiteSpace(_roomType)) &&
                         string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                          room.DISTRICT == _district
                                      select room).ToList();


                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                         room.DISTRICT == _district
                                     select room).Count();

                }
                else if (((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                         string.IsNullOrWhiteSpace(_branch) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         string.IsNullOrWhiteSpace(_roomType) &&
                         string.IsNullOrWhiteSpace(_bedType)))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name
                                     select room).Count();

                }
                else if (((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                         (!string.IsNullOrWhiteSpace(_branch)) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         string.IsNullOrWhiteSpace(_roomType) &&
                         string.IsNullOrWhiteSpace(_bedType)))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&
                                         room.BRANCHNAME == _branch
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&
                                        room.BRANCHNAME == _branch
                                     select room).Count();
                }
                else if (((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                         (!string.IsNullOrWhiteSpace(_branch)) &&
                  string.IsNullOrWhiteSpace(_district) &&
                  string.IsNullOrWhiteSpace(_roomType) &&
                  (!string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&
                                         room.BRANCHNAME == _branch &&
                                         room.BEDTYPE == _bedType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&
                                        room.BRANCHNAME == _branch &&
                                        room.BEDTYPE == _bedType
                                     select room).Count();
                }
                else if (((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                    (string.IsNullOrWhiteSpace(_branch)) &&
                     string.IsNullOrWhiteSpace(_district) &&
                     string.IsNullOrWhiteSpace(_roomType) &&
                     (!string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&

                                         room.BEDTYPE == _bedType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&

                                        room.BEDTYPE == _bedType
                                     select room).Count();
                }
                else if (((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                    (string.IsNullOrWhiteSpace(_branch)) &&
                     string.IsNullOrWhiteSpace(_district) &&
                    (!string.IsNullOrWhiteSpace(_roomType)) &&
                    (string.IsNullOrWhiteSpace(_bedType))))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&

                                         room.ROOMTYPE == _roomType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&

                                        room.ROOMTYPE == _roomType
                                     select room).Count();
                }
                else if ((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                         (!string.IsNullOrWhiteSpace(_branch)) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         (!string.IsNullOrWhiteSpace(_roomType)) &&
                         string.IsNullOrWhiteSpace(_bedType))
                {

                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&
                                         room.BRANCHNAME == _branch &&
                                         room.ROOMTYPE == _roomType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&
                                        room.BRANCHNAME == _branch &&
                                        room.ROOMTYPE == _roomType
                                     select room).Count();
                }

                else if ((!string.IsNullOrWhiteSpace(_hotel_name)) &&
                         (!string.IsNullOrWhiteSpace(_branch)) &&
                         string.IsNullOrWhiteSpace(_district) &&
                         (!string.IsNullOrWhiteSpace(_roomType)) &&
                         (!string.IsNullOrWhiteSpace(_bedType)))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.HOTEL_NAME == _hotel_name &&
                                         room.BRANCHNAME == _branch &&
                                         room.ROOMTYPE == _roomType &&
                                         room.BEDTYPE == _bedType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.HOTEL_NAME == _hotel_name &&
                                        room.BRANCHNAME == _branch &&
                                        room.ROOMTYPE == _roomType &&
                                        room.BEDTYPE == _bedType
                                     select room).Count();
                }
                else if (string.IsNullOrWhiteSpace(_hotel_name) &&
                        (string.IsNullOrWhiteSpace(_branch)) &&
                        string.IsNullOrWhiteSpace(_district) &&
                        (!string.IsNullOrWhiteSpace(_roomType)) &&
                        (!string.IsNullOrWhiteSpace(_bedType)))
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.ROOMTYPE == _roomType &&
                                         room.BEDTYPE == _bedType
                                      select room).ToList();

                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.ROOMTYPE == _roomType &&
                                        room.BEDTYPE == _bedType
                                     select room).Count();
                }
                else
                {
                    ViewData.Model = (from room in _db.HOTEL_ROOM_INFO
                                      where room.COUNTRY == _country &&
                                         room.ROOMTYPE == _roomType &&
                                         room.BEDTYPE == _bedType &&
                                         room.HOTEL_NAME == _hotel_name &&
                                         room.BRANCHNAME == _branch

                                      select room).ToList();


                    noResultFound = (from room in _db.HOTEL_ROOM_INFO
                                     where room.COUNTRY == _country &&
                                        room.ROOMTYPE == _roomType &&
                                        room.BEDTYPE == _bedType &&
                                        room.HOTEL_NAME == _hotel_name &&
                                        room.BRANCHNAME == _branch

                                     select room).Count();
                }

                ViewData["noResultFound"] = noResultFound;
                return View();
            }
            catch
            {
                return RedirectToAction("Error", "Home");
            }
        }



    }
}
